package com.anti.modular.owner.ownerleasebill.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.api.Result;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.owner.ownerleasebill.param.OwnerLeaseBillEditParam;
import com.anti.modular.owner.ownerleasebill.param.OwnerLeaseBillParam;
import com.anti.modular.owner.ownerleasebill.result.LeaseBillPlanResult;
import com.anti.modular.owner.ownerleasebill.service.OwnerLeaseBillService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 業主賬單控制器
 *
 * @author anti
 * @date 2021-05-20 14:25:38
 */
@RestController
@RequestMapping("ownerLeaseBill")
public class OwnerLeaseBillController {

    @Resource
    private OwnerLeaseBillService ownerLeaseBillService;

    /**
     * 查询業主賬單
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @GetMapping("page")
    public Result page(PageParam pageParam, OwnerLeaseBillParam ownerLeaseBillParam) {
        return Result.data(ownerLeaseBillService.page(pageParam,ownerLeaseBillParam));
    }

    @GetMapping("getOwnerBillNum")
    public Result getOwnerBillNum(){
        return Result.data(ownerLeaseBillService.getOwnerBillNum());
    }

    @GetMapping("ownerLeaseBillPageByLeaseId")
    public Result ownerLeaseBillPageByLeaseId(PageParam pageParam, OwnerLeaseBillParam ownerLeaseBillParam) {
        return Result.data(ownerLeaseBillService.ownerLeaseBillPageByLeaseId(pageParam,ownerLeaseBillParam));
    }

    /**
     * 添加業主賬單
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @PostMapping("add")
    @BusinessLog(title = "業主賬單_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(OwnerLeaseBillParam.add.class) OwnerLeaseBillParam ownerLeaseBillParam) {
            ownerLeaseBillService.add(ownerLeaseBillParam);
        return Result.success("新增成功");
    }

    /**
     * 删除業主賬單
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @PostMapping("delete")
    @BusinessLog(title = "業主賬單_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(OwnerLeaseBillParam.delete.class) OwnerLeaseBillParam ownerLeaseBillParam) {
            ownerLeaseBillService.delete(ownerLeaseBillParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑業主賬單
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @PostMapping("edit")
    @BusinessLog(title = "業主賬單_修改", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(OwnerLeaseBillEditParam.edit.class) OwnerLeaseBillEditParam ownerLeaseBillParam) {
            ownerLeaseBillService.edit(ownerLeaseBillParam);
        return Result.success("修改成功");
    }
    @PostMapping("editJz")
    @BusinessLog(title = "業主賬單_交租", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result editJz(@RequestBody @Validated(OwnerLeaseBillParam.editJz.class) OwnerLeaseBillParam ownerLeaseBillParam) {
        ownerLeaseBillService.editJz(ownerLeaseBillParam);
        return Result.success("交租成功");
    }
    @PostMapping("editCxdz")
    @BusinessLog(title = "業主賬單_撤銷到賬", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result editCxdz(@RequestBody @Validated(OwnerLeaseBillParam.editCxdz.class) OwnerLeaseBillParam ownerLeaseBillParam) {
        ownerLeaseBillService.editCxdz(ownerLeaseBillParam);
        return Result.success("交租成功");
    }

    @PostMapping("editQsTz")
    @BusinessLog(title = "業主賬單_退租清算", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result editQsTz(@RequestBody @Validated(OwnerLeaseBillParam.editJz.class) OwnerLeaseBillParam ownerLeaseBillParam) {
        ownerLeaseBillService.editQsTz(ownerLeaseBillParam);
        return Result.success("退租清算成功");
    }

    @PostMapping("editBillPlan")
    @BusinessLog(title = "業主賬單_修改賬單租金", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result editBillPlan(@RequestBody LeaseBillPlanResult ownerLeaseBillParam) {
        ownerLeaseBillService.editBillPlan(ownerLeaseBillParam);
        return Result.success("修改成功");
    }

    /**
     * 查看業主賬單
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @GetMapping("detail")
    public Result detail(@Validated(OwnerLeaseBillParam.detail.class) OwnerLeaseBillParam ownerLeaseBillParam) {
        return Result.data(ownerLeaseBillService.detail(ownerLeaseBillParam));
    }
    /**
     * 查看業主賬單
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @GetMapping("detailByBillId")
    public Result detailByBillId(@Validated(OwnerLeaseBillParam.detail.class) OwnerLeaseBillParam ownerLeaseBillParam) {
        return Result.data(ownerLeaseBillService.detailByBillId(ownerLeaseBillParam));
    }
    /**
     * 業主賬單列表
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @GetMapping("list")
    public Result list(OwnerLeaseBillParam ownerLeaseBillParam) {
        return Result.data(ownerLeaseBillService.list(ownerLeaseBillParam));
    }


    @GetMapping("getOwnerBillDetailReadOnly/{billId}")
    public Result getOwnerBillDetailReadOnly(@PathVariable(name = "billId") Long billId) {
        return Result.data(ownerLeaseBillService.getOwnerBillDetailReadOnly(billId));
    }

    @GetMapping("getOwnerBillDetailForEdit/{billId}")
    public Result getOwnerBillDetailForEdit(@PathVariable(name = "billId") Long billId) {
        return Result.data(ownerLeaseBillService.getOwnerBillDetailForEdit(billId));
    }


    /**
     * 获取账单计划列表
     *
     * @author anti
     * @date 2021-05-20 14:25:38
     */
    @GetMapping("getBillListByLeaseId/{leaseId}")
    public Result getBillListByLeaseId(@PathVariable(name = "leaseId") Long leaseId) {
        return Result.data(ownerLeaseBillService.getBillListByLeaseId(leaseId));
    }

}
